package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.databinding.ItemVehicleOwnerBinding;
import com.swgk.core.util.LogUtil;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.CarHallEntity;
import com.sgb.kjwl.model.entity.transport.CarsSourcesEntiity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/***
 * 新车主列表
 */
public class VehicleOwner1Adapter extends BaseRecycleAdapter<CarHallEntity> {
    private static final String TAG = "VehicleOwnerAdapter";

    public VehicleOwner1Adapter(Context context, List<CarHallEntity> datas) {
        super(context, R.layout.item_vehicle_owner, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final CarHallEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemVehicleOwnerBinding binding = (ItemVehicleOwnerBinding) holder.getmBinding();
        if (entity == null) {
            LogUtil.d(TAG, "VehicleOwnerAdapter entity is null");
            return;
        }

        TextView titleView = holder.itemView.findViewById(R.id.title_view);
        StringBuffer stringBuffer = new StringBuffer();
        if (!TextUtils.isEmpty(entity.getCarTypeName())) {
            stringBuffer.append(entity.getCarTypeName());
            stringBuffer.append("/");
        }
        if (!TextUtils.isEmpty(entity.getCarLenName())) {
            stringBuffer.append(entity.getCarLenName());
            stringBuffer.append("/");
        }
        if (entity.getWeight() != null) {
            stringBuffer.append(entity.getWeight() + "吨");
            stringBuffer.append("/");
        }
        if (entity.getIsDumper() != null) {
            stringBuffer.append(entity.getIsDumper() == 1 ? "自卸" : "非自卸");
        }else {
            stringBuffer.append("非自卸");
        }
        titleView.setText(stringBuffer.toString());

        TextView textView = holder.itemView.findViewById(R.id.tv_city);
        if (!TextUtils.isEmpty(entity.getProvinceName())){
            binding.layoutAddress.setVisibility(View.VISIBLE);
            textView.setText(entity.getProvinceName() + entity.getCityName() + entity.getDistrictName());
        }else {
            binding.layoutAddress.setVisibility(View.INVISIBLE);
            textView.setText("");
        }
    }
}
